package com.jiamao.lib.api;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;


/**
 * Created by wby on 2016/5/18.
 * asd
 */
public class OkHttpUtils {

    private static OkHttpClient singleton;

    public static OkHttpClient getInstance() {
        if (singleton == null) {
            synchronized (OkHttpUtils.class) {
                if (singleton == null) {



                    Interceptor mTokenInterceptor = new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request originalRequest = chain.request();
                            //本地的token和uid没有 就不添加头
//                            if (Your.sToken == null) {
//                                return chain.proceed(originalRequest);
//                            }
                            Request authorised = originalRequest.newBuilder()
//                                    .header("uid", SharedPreferencesUtil.getInstant().getStrPreferenceByParamName(MyApplication.app, Constant.sp.UID))
//                                    .header("token",SharedPreferencesUtil.getInstant().getStrPreferenceByParamName(MyApplication.app, Constant.sp.TOKEN))
//                                    .header("platform","android")
//                                    .header("appversion",MyApplication.APPVERSION)
//                                    .header("deviceid",MyApplication.IMEI)
//                                    .header("moble",MyApplication.MOBLE).
//                                     header("mobleversion",MyApplication.MOBLE_VERSION)
                                    .build();
                            return chain.proceed(authorised);
                        }
                    };
                    singleton = new OkHttpClient().newBuilder()
                            .addInterceptor(mTokenInterceptor)

                            .build();

                }
            }
        }
        return singleton;
    }
}
